<template>
  <el-form ref="form" :model="form" label-width="100px">
    <el-form-item label="通道别名">
      <el-input disabled v-model="form.channelCode"></el-input>
    </el-form-item>
    <el-form-item label="通道中文名称">
      <el-input v-model="form.channelName"></el-input>
    </el-form-item>
    <el-form-item label="通道类型">
      <el-select disabled v-model="form.tradeType" >
        <el-option :label="tradeTypeItems[form.tradeType]" :value="form.tradeType" ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="是否必须鉴权">
      <el-radio-group v-model="form.authentication">
        <el-radio disabled :label="1">是</el-radio>
        <el-radio disabled :label="0">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="鉴权类型">
      <el-select disabled v-model="form.authenticationType" >
        <el-option :label="getAuthenticationType[form.authenticationType]" :value="form.authenticationType" ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="优先级">
      <el-input v-model="form.priority"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input type="textarea" v-model="form.remark"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">确定</el-button>
      <el-button @click="onCanel">取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
  import { updateChannel } from '@/services/getData'
  export default {
    name: 'channel-restriction-edit',
    props: {
      form: {
        type: Object,
        default() {
          return {
            channelCode: "", // 通道别名, 
            channelName: "", // 通道中文名称,
            tradeType: 1, // 交易类型,
            authentication: 1, // 是否需要鉴权,
            authenticationType: 1, // 鉴权类型
            priority: 1,  // 优先级
            remark: "111111"  // 备注
          }
        }
      }
    },
    created() {
      this.tradeTypeItems = this.GLOBAL.getChanelType()
      this.getAuthenticationType = this.GLOBAL.getAuthenticationType()
    },
    methods: {
      onSubmit() {
        let formDataStr = this.GLOBAL.ObjectCopy(this.form)
        delete formDataStr["createTime"]
        delete formDataStr["tradeTypeStr"]
        delete formDataStr["updateTime"]
        delete formDataStr["statusStr"]
        formDataStr["operatorName"] = sessionStorage.getItem('ms_username')
        formDataStr["operatedMenu"] = "代收通道管理"
        formDataStr["operatedButton"] = "编辑"
        
        updateChannel(formDataStr).then(
          res => {
            if (res.resultCode == 1) {
              this.$message({
                type: 'success',
                message: "提交成功"
              });
              this.$emit("chanelClose",1)
            } else {
              this.$notify.error({
                title: '错误',
                message: res.errorDesc
              });
            }
          }
        )
      },
      onCanel() {
        this.$emit("chanelClose",1)
      }
    }
  }
</script>